<?php
/**
 * 版权所有: 合肥讯邦网络科技有限公司 [http://www.ahxb.cc]
 * 公司电话: 0551-63668080
 * 作    者: 叶程鹏
 * 修改时间: 2018/07/19 9:56
 * 功能说明: 首页部分
 */
namespace Home\Controller;
use XBCommon\XBCache;
use Admin\Controller\System\TokenHelperController;
use Moxie\Moxie;
class IndexController extends HomeController{
 const T_MOBILE='renzen_mobile';//手机认证表
    //口子首页
    public function kouzi(){
    	//查找最新4条记录
    	$itemlist=M('tg_items')->field('ID,Name,Intro,Logurl,Url')->where(array('IsTui'=>'1','Status'=>'1','IsDel'=>'0'))->select();
    	$this->assign(array(
    		'itemlist'=>$itemlist,
    		));
    	$this->display();
    }
	  public function baogao(){
	  	 $id=I('get.id',0,'intval');
	     $mobileinfos=M('renzen_cards')->where(array('ID'=>$id,'IsDel'=>'0'))->getField('Yddatas');
	     $youdun=unserialize($mobileinfos);
	  	 $this->assign('data',$youdun);
         $this->display();
    }
//	 魔杖2.0
public function heihui(){
		$id=I('get.id',0,'intval'); 
	    $memberdata=M('mem_info')->field('ID,TrueName,IDCard,Mobile')->where(array('ID'=>$id))->find();//获取用户表信息
		$Moxie= new \Moxie\Moxie;
	    $name=$memberdata['TrueName']; 
        $idcard=$memberdata['IDCard'];
        $mobile=$memberdata['Mobile'];
		$qq_number='';
		$method = "moxie.api.risk.magicwand2.application";
		$data=$Moxie->getMoZhangContent($name,$idcard,$mobile,$qq_number,$method);
		$data=json_decode($data,1);
        $type=$data['data']['auth_queried_detail']['register_info']['org_types'];
		foreach ($type as $k => $v) {
					if($v=='BANK'){
						$type[$k]='银行';
					}
					if($v=='CASH_LOAN'){
						$type[$k]='现金贷';
					}
					if($v=='COMPENSATION'){
						$type[$k]='信用卡代偿';
					}
					if($v=='CONSUMSTAGE'){
						$type[$k]='消费分期';
					}
					if($v=='CREDITPAY'){
						$type[$k]='信用支付';
					}
					if($v=='DATACOVERGE'){
						$type[$k]='数据聚合平台';
					}		
					if($v=='DIVERSION'){
						$type[$k]='导流平台';
					}
					if($v=='P2P'){
						$type[$k]='P2P理财';
					}
					if($v=='ZHENGXIN'){
						$type[$k]='征信机构';
					}
		}
		$str='';
		foreach ($type as $k => $v) {
			$str=$str.$v.'/';
		}
		$data['data']['auth_queried_detail']['register_info']['org_types']=$str;
		
		
		
		
//		p($data['data']['auth_queried_detail']['queried_analyze']['org_type']);die;
		
		
//	 p($data['data']);
		
		
		$this->assign('postDate',$data['data']);
		   $this->display();
		
	
}
//多头

//public function duotou(){
//		$id=I('get.id',0,'intval'); 
//	    $memberdata=M('mem_info')->field('ID,TrueName,IDCard,Mobile')->where(array('ID'=>$id))->find();//获取用户表信息
//	    $method = "moxie.api.risk.magicwand2.multi-info";
//	   
//	echo 3333;die;
//	
//}

	  
	  
//	  新颜雷达
	   public function xinyanbaogao(){
	  	$id=I('get.id',0,'intval'); 
	    $memberdata=M('mem_info')->field('TrueName,IDCard,Mobile')->where(array('ID'=>$id))->find();//获取用户表信息
	    $this->assign('memberdata',$memberdata);
	    $leidadata=M('ss_bgdata')->where(array('UserID'=>$id,'status'=>'1'))->find();//获取用户表信息
	    $leidadata['data']=json_decode($leidadata['data'],1);
		$this->assign('leidadata',$leidadata);
        $this->display();
        }
 //	  征信
	   public function zhengxin(){
	  	$id=I('get.id',0,'intval'); 
	    $memberdata=M('mem_info')->field('ID,TrueName,IDCard,Mobile')->where(array('ID'=>$id))->find();//获取用户表信息
	    $this->assign('memberdata',$memberdata);
//		查询征信分数据 如果有 就调用 没有就调用接口查询
		$zhegnxinfen=M('ss_user_credit')->where(array('UserID'=>$id))->find();//征信分
		 if($zhegnxinfen){
		    $this->assign('zhegnxinfen',$zhegnxinfen);
	    }else{
//		征信分 
		$post_data['data']['sync']='1';
		$post_data['data']['name']=$memberdata['TrueName'];
		$post_data['data']['phoneNo']=$memberdata['Mobile'];
		$post_data['data']['idCardNo']=$memberdata['IDCard'];
		$post_data['data']['loanType']='1';
		$post_data=json_encode($post_data,JSON_UNESCAPED_UNICODE );
        //获取token
        $urlPath = '/daas/v1/tasks';
        $method = 'POST';
        $queryParam = 'appKey=t5suvrvzwv&taskType=credit_score';
        $body = $post_data;
        $expireTime = time() + 3600;
        $tokenObj = new TokenHelperController();
        $token = $tokenObj->generateToken($urlPath,$method,$queryParam,$body,$expireTime);
        //获取用户征信信息
        $zhengxinfedata=zhengxinfen($body,$token['token']);
        $zhengxinfedata = json_decode($zhengxinfedata,true);
//		p($zhengxinfedata);die;
	    $zhegnxin['create_time'] = date('Y-m-d h:i:s', time());
	    $zhegnxin['Score']=$zhengxinfedata['taskResult']['score'];
		$zhegnxin['UserID']=$memberdata['ID'];
        $zhegnxinid = M('ss_user_credit')->add($zhegnxin);
		$zhegnxinfen=M('ss_user_credit')->where(array('UserID'=>$id))->find();//征信分
		$this->assign('zhegnxinfen',$zhegnxinfen);
	    }
	    $heidan=M('ss_user_blacklist')->where(array('UserID'=>$id))->find();//黑名单
	    
	   
	    if($heidan){
		    $this->assign('heidan',$heidan);
	    }else{
 //		获取黑名单信息
		$post_dataQ['data']['sync']='1';
		$post_dataQ['data']['name']=$memberdata['TrueName'];
		$post_dataQ['data']['phoneNo']=$memberdata['Mobile'];
		$post_dataQ['data']['idCardNo']=$memberdata['IDCard'];
		$post_dataQ['data']['loanType']='1';
		$post_dataQ=json_encode($post_dataQ,JSON_UNESCAPED_UNICODE );
        //获取token
        $urlPath = '/daas/v1/tasks';
        $method = 'POST';
        $body = $post_dataQ;
        $expireTime = time() + 3600;
        $tokenObj = new TokenHelperController();
        $queryParam = 'appKey=t5suvrvzwv&taskType=credit_black';
		$token = $tokenObj->generateToken($urlPath,$method,$queryParam,$body,$expireTime);
		$heimingdandata=heimingdan($body,$token['token']);
        $heimingdandata = json_decode($heimingdandata,true);
//		p($heimingdandata);die;
			$heimingdan['create_time'] = date('Y-m-d h:i:s', time());
			$heimingdan['IsBan']=$heimingdandata['taskResult']['isBan'];
			$heimingdan['Black1']=$heimingdandata['taskResult']['black1'];
			$heimingdan['Black2']=$heimingdandata['taskResult']['black2'];
			$heimingdan['Black3']=$heimingdandata['taskResult']['black3'];
			$heimingdan['Black4']=$heimingdandata['taskResult']['black4'];
			$heimingdan['UserID']=$memberdata['ID'];
            $heimingdanid = M('ss_user_blacklist')->add($heimingdan);
            $heidanyuanshi=M('ss_user_blacklist')->where(array('UserID'=>$id))->find();//黑名单
          	$this->assign('heidan',$heidanyuanshi);
	    }
        $this->display();
    }
	   
//	   黑名单
	   public function heimingdanyemian(){               
	  	 $id=I('get.id',0,'intval'); 
	     $memberdata=M('mem_info')->field('TrueName,IDCard,Mobile')->where(array('ID'=>$id))->find();
		 $url='http://credit.beikeyuntiao.com/api/black-jdb/get-report';
		 $token=M('sys_inteparameter')->where(['ParaName'=>'xinyan'])->getField('ParaValue');//商户号
	     $postDate = [
	     "phone"  => $memberdata['Mobile'],
	     "name"   => $memberdata['TrueName'],
	     "idcard" => $memberdata['IDCard']
		 ];
		$header = [
		    "X-Mall-Token: " . $token,
		    'Content-Type: text/html; charset=utf-8',
		];
		$postDate['time']=date('Y-m-d h:i:s',time());
        $response = doGet($url,$postDate,$header);
//		p($response);
		$this->assign('postDate',$postDate);
//		p($postDate);
	  	$this->assign('data',$response);
        $this->display();
    }

//收集数据
//手机号 真是姓名 身份证号码  会员ID
    public function get_date(){
    $rqend = date('Y-m-d');//截止时间
	$rqstart=date("Y-m-d",strtotime("-1 day"));//开始时间
    $map['RegTime']  = array('between',array($rqstart,$rqend));
	$data=M('mem_info')->where($map)->field('ID,Mobile,TrueName,IDcard,RegTime')->select();  
//	P($data);
	foreach ($data as $k => $v) {
//		P($v);DIE;
			$LoanStatus=M('loans_applylist')->where(['UserID'=>$v['ID']])->getField('LoanStatus');
			if($LoanStatus){
				if($LoanStatus==0){
					$data[$k]['LoanStatus']='申请中';
				}
				if($LoanStatus==1){
					$data[$k]['LoanStatus']='放款中';
				}
				if($LoanStatus==2){
					$data[$k]['LoanStatus']='已放款 ';
				}
				if($LoanStatus==3){
					$data[$k]['LoanStatus']='已完成';
				}
				if($LoanStatus==4){
					$data[$k]['LoanStatus']='已取消';
				}
				if($LoanStatus==5){
					$data[$k]['LoanStatus']='已拒绝';
				}
				if($LoanStatus==6){
					$data[$k]['LoanStatus']='银行打款中';
				}
				if($LoanStatus==7){
					$data[$k]['LoanStatus']='处理中';
				}
				
//				0申请中 1放款中 2已放款 3已完成 4已取消 5人已拒绝6银行打款中7处理中
				
			}else{
				$data[$k]['LoanStatus']='未申请';
			}
	}
	  echo json_encode(array('code'=>'1','data'=>$data));
    }


}